SQL Server Query Tuning and Optimization by Benjamin Nevarez
Author:Benjamin Nevarez
Language: eng
Format: epub
Publisher: Packt Publishing Pvt Ltd
Published: 2022-07-22T00:00:00+00:00
Missing indexes
SQL Server provides a second approach that can help you find useful indexes for your existing queries. Although not as powerful as the DTA, this option, called the missing indexes feature, does not require the database administrator to decide when tuning is needed, to explicitly identify what workload represents the load to tune, or to run any tool. This is a lightweight feature that is always on and, like the DTA, was also introduced with SQL Server 2005. Letâs take a look at what it does.
During optimization, the query optimizer defines what the best indexes for a query are and, if these indexes donât exist, it will make this index information available in the query XML plan (which is also available in a graphical plan in SQL Server Management Studio 2008 or later). Alternatively, it will aggregate this information for optimized queries since the instance was started, and make it all available on the sys.dm_db_missing_index DMVs. Note that just by displaying this information, the query optimizer is not only warning you that it might not be selecting an efficient plan, but it is also showing you which indexes may help to improve the performance of your query. In addition, database administrators and developers should be aware of the limitations of this feature, as described in âLimitations of the Missing Indexes Feature,â at http://msdn.microsoft.com/en-us/library/ms345485(v=sql.105).aspx.
So, with all that in mind, letâs take a quick look to see how this feature works. Create the dbo.SalesOrderDetail table on the AdventureWorks2019 database by running the following statement:
SELECT * INTO dbo.SalesOrderDetail
FROM Sales.SalesOrderDetail
Run the following query and request a graphical or XML execution plan:
SELECT * FROM dbo.SalesOrderDetail
WHERE SalesOrderID = 43670 AND SalesOrderDetailID > 112
This query could benefit from an index on the SalesOrderID and SalesOrderDetailID columns, but no missing indexes information is shown this time. One limitation of the missing indexes feature that this example has revealed is that it does not work with a trivial plan optimization. You can verify that this is a trivial plan by looking at the graphical plan properties, shown as Optimization Level TRIVIAL, or by looking at the XML plan, where StatementOptmLevel is shown as TRIVIAL. You can avoid trivial plan optimization in several ways, as explained in Chapter 3, The Query Optimizer. In our case, weâre just going to create a non-related index by running the following statement:
CREATE INDEX IX_ProductID ON dbo.SalesOrderDetail(ProductID)
What is significant about this is that, although the index created will not be used by our previous query, the query no longer qualifies for a trivial plan. Run the query again, and this time the XML plan will contain the following entry:
<MissingIndexes>
<MissingIndexGroup Impact=â99.7142â>
<MissingIndex Database=â[AdventureWorks2019]â Schema=â[dbo]â
Table=â[SalesOrderDetail]â>
<ColumnGroup Usage=âEQUALITYâ>
<Column Name=â[SalesOrderID]â ColumnId=â1â />
</ColumnGroup>
<ColumnGroup Usage=âINEQUALITYâ>
<Column Name=â[SalesOrderDetailID]â ColumnId=â2â />
</ColumnGroup>
</MissingIndex>
</MissingIndexGroup>
</MissingIndexes>
The MissingIndexes entry in the XML plan can show up to three groupsâequality, inequality, and includedâand the first two are shown in this example using the ColumnGroup attribute. The information contained in these groups can be used to create the missing index; the key of the index can be built by using the equality columns,
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Coding Theory | Localization |
Logic | Object-Oriented Design |
Performance Optimization | Quality Control |
Reengineering | Robohelp |
Software Development | Software Reuse |
Structured Design | Testing |
Tools | UML |
Deep Learning with Python by François Chollet(12519)
Hello! Python by Anthony Briggs(9866)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9756)
The Mikado Method by Ola Ellnestam Daniel Brolund(9746)
Dependency Injection in .NET by Mark Seemann(9292)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8257)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7740)
Grails in Action by Glen Smith Peter Ledbrook(7666)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7515)
Becoming a Dynamics 365 Finance and Supply Chain Solution Architect by Brent Dawson(6739)
Microservices with Go by Alexander Shuiskov(6503)
Practical Design Patterns for Java Developers by Miroslav Wengner(6404)
Test Automation Engineering Handbook by Manikandan Sambamurthy(6382)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6376)
Angular Projects - Third Edition by Aristeidis Bampakos(5759)
The Art of Crafting User Stories by The Art of Crafting User Stories(5292)
NetSuite for Consultants - Second Edition by Peter Ries(5236)
Demystifying Cryptography with OpenSSL 3.0 by Alexei Khlebnikov(5052)
Kotlin in Action by Dmitry Jemerov(5017)
